package com.example.demo.service.Impl;

        import com.example.demo.bean.Comment;
        import com.example.demo.bean.CommentExample;
        import com.example.demo.dao.CommentMapper;
        import com.example.demo.service.ICommentService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        import org.springframework.util.StringUtils;

        import javax.annotation.Resource;
        import java.util.Date;
        import java.util.List;
@Service
public class CommentServiceImpl implements ICommentService {
    @Resource
    private CommentMapper commentMapper;
    @Override
    public List<Comment> query(Long id,String content) {
        CommentExample example=new CommentExample();
        if (!StringUtils.isEmpty(id)) {
            example.createCriteria().andIdEqualTo(id);
        }
        if(!StringUtils.isEmpty(content)){
            example.createCriteria().andContentEqualTo(content);
        }
        List<Comment> list=commentMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Comment comment) {
        if(comment.getId()==null){
            comment.setCommentTime(new Date().getTime());
            commentMapper.insert(comment);
        }else{
            commentMapper.updateByPrimaryKey(comment);
        }
    }

    @Override
    public void deleteById(long id) {
        commentMapper.deleteByPrimaryKey(id);
    }
}
